package com.shixianchen.review_the_day_before.day5;

import com.shixianchen.utils.Utils;
import com.shixianjun.sort.Sortable;
import com.shixianjun.sort.SortableElement;

/**
 * @program: algorithm
 * @description:
 * @author: SXC
 * @create: 2022-11-08 12:24
 **/
public class BubbleSort implements Sortable {
    @Override
    public void sort(SortableElement[] arr) {
        int n = arr.length;
        for (int i = 0; i < n-1; i++) {
            boolean flag = true;
            for (int j = 0; j < n-1-i; j++) {

                if (arr[j].value > arr[j+1].value){
                    flag = false;
                    Utils.swap(arr,j,j+1);
                }
            }
            if (flag){
                break;
            }

        }
    }
}
